package com.sptpc.demo.service.impl;

import com.sptpc.demo.mapper.DrinkMapper;
import com.sptpc.demo.model.Drink;
import com.sptpc.demo.service.IDrinkService;
import com.sptpc.demo.vo.DrinkWithCategoryNameVo;
import com.sptpc.demo.vo.DrinkWithCategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DrinkService implements IDrinkService {
    @Autowired
    public DrinkMapper drinkMapper;

    @Override
    public List<DrinkWithCategoryVo> getAllDrinks() {
        return drinkMapper.selectDrinksWithCategory();
    }

    @Override
    public void addNewDrink(Drink savedDrink, Integer categoryId) {
        drinkMapper.insert(savedDrink);
    }

    @Override
    public Drink getDrinkById(Long id) {
        return drinkMapper.selectByPrimaryKey(id);
    }

    @Override
    public void updateDrink(Drink drink) {
        drinkMapper.updateByPrimaryKeySelective(drink);
    }

    @Override
    public void deleteDrinkById(Long id) {
       drinkMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<DrinkWithCategoryNameVo> getAllDrinksWithCategoryName() {
        return drinkMapper.selectDrinksWithCategoryName();
    }
}
